@inherits MiniRazor.TemplateBase<CodeEntity>
@namespace MicroCloud.CodeGeneration.Generates
@using System;
@using System.Collections.Generic;
@using System.Linq;
@using MicroCloud.CodeGeneration
@using MicroCloud.CodeGeneration.Database
@using MicroCloud.CodeGeneration.Dtos
@using MicroCloud.CodeGeneration.Entities
@using MicroCloud.CodeGeneration.Generates
@{
    CodeEntity entity = Model;
}
using InputDto = @(entity.Module.Namespace).Dtos.@(entity.Name)InputDto;
using OutputDto = @(entity.Module.Namespace).Dtos.@(entity.Name)OutputDto;
using Entity = @(entity.Module.Namespace).Entities.@(entity.Name)Entity;

namespace @(entity.Module.Project.NamespacePrefix).Api.Areas.Admin.Controllers.@(entity.Module.Name)
{
    /// <summary>
    /// 管理-@(entity.Display)
    /// </summary>
    [Description("管理-@(entity.Display)")]
    [ModuleInfo(Code = "@(entity.Name)", Name = "@(entity.Display)", OrderNo = 99, Position = "@(entity.Module.Name)", PositionName = "@(entity.Module.Display)模块")]
    public class @(entity.Name)Controller: AdminControllerBase
    {
        /// <summary>
        /// 获取 @(entity.Display)服务
        /// </summary>
        protected @(entity.Name)Store @(entity.Name)Store => ServiceProvider.GetService<@(entity.Name)Store>();
@if (entity.Listable)
{
        <text>
        /// &lt;summary&gt;
        /// 读取@(entity.Display)列表
        /// &lt;/summary&gt;
        [ModuleInfo]
        [HttpPost]
        [Description("读取")]
        public PageData<OutputDto> Read(PageRequest request)
        {
            Check.NotNull(request, nameof(request));
            IFunction function = this.GetExecuteFunction();

            Expression&lt;Func&lt;Entity, bool&gt;&gt; predicate = FilterService.GetExpression&lt;Entity&gt;(request.FilterGroup);
            var page = CacheService.ToPageCache&lt;Entity, OutputDto&gt;(@(entity.Name)Store.Entities, predicate, request.PageCondition, function);

            return page.ToPageData();
        }
</text>
}
@if (entity.Addable)
{
        <text>
        /// &lt;summary&gt;
        /// 新增@(entity.Display)实体
        /// &lt;/summary&gt;
        /// &lt;param name="dtos"&gt;新增@(entity.Display)信息&lt;/param&gt;
        /// &lt;returns&gt;JSON操作结果&lt;/returns&gt;
        [Description("新增")]
        [DependOnFunction(nameof(Read))]
        [ModuleInfo]
        [UnitOfWork]
        [HttpPost]
        public async Task&lt;AjaxResult&gt; Create(InputDto[] dtos)
        {
            Check.NotNull(dtos, nameof(dtos));
            List&lt;string&gt; ids = new();
            List&lt;OutputDto&gt; outputDtos = new();
            foreach (var dto in dtos)
            {
                var result = await @(entity.Name)Store.InsertByDtoAsync(dto);
                if (!result.Succeeded)
                {
                    return result.ToAjaxResult();
                }
                ids.Add(dto.Id.ToString());
                outputDtos.Add(dto.MapTo&lt;OutputDto&gt;());
            }
            return AjaxResult.Success(outputDtos, string.Format("实体“{0}”创建成功", ids.ExpandAndToString()));
        }
</text>
}
@if (entity.Updatable)
{
        <text>
        /// &lt;summary&gt;
        /// 更新@(entity.Display)实体
        /// &lt;/&lt;summary&gt;
        /// &lt;param name="dtos"&gt;@(entity.Name)信息&lt;/param&gt;
        /// &lt;returns&gt;JSON操作结果&lt;/returns&gt;
        [HttpPost]
        [ModuleInfo]
        [DependOnFunction(nameof(Read))]
        [UnitOfWork]
        [Description("更新")]
        public async Task&lt;AjaxResult&gt; Update(InputDto[] dtos)
        {
            Check.NotNull(dtos, nameof(dtos));
            List&lt;string&gt; ids = new();
            List&lt;OutputDto&gt; outputDtos = new();
            foreach (var dto in dtos)
            {
                var result = await @(entity.Name)Store.UpdateByDtoAsync(dto);
                if (!result.Succeeded)
                {
                    return result.ToAjaxResult();
                }
                ids.Add(dto.Id.ToString());
                outputDtos.Add(dto.MapTo&lt;InputDto, OutputDto&gt;());
            }
            return AjaxResult.Success(outputDtos, I18N.T("实体“{0}”更新成功", ids.ExpandAndToString()));
        }
</text>
}
@if (entity.Updatable)
{
        <text>
        /// &lt;summary&gt;
        /// 删除@(entity.Display)实体
        /// &lt;/summary&gt;
        /// &lt;param name="ids"&gt;要删除的编号&lt;/param&gt;
        /// &lt;returns&gt;JSON操作结果&lt;/returns&gt;
        [HttpPost]
        [ModuleInfo]
        [DependOnFunction(nameof(Read))]
        [UnitOfWork]
        [Description("删除")]
        public async Task&lt;AjaxResult&gt; Delete(Guid[] ids)
        {
            Check.NotNull(ids, nameof(ids));
            var result = await @(entity.Name)Store.DeleteAsync(ids);
            return result.ToAjaxResult();
        }
</text>
}
    }
}